<template>
  <div>
    <button type="button" @click="bar">调用父组件方法</button>
    <button type="button" @click="post">同步修改父组件的值</button>
    <ul>
      <li v-for="(item, index) of names" :key="index" @click="sendVal(item)">{{item}}</li>
    </ul>
    <hr />
    <p>{{aa}}</p>
  </div>
</template>

<script>
export default {
  props: {
    names: {
      type: Array
    },
    aa: {
      type: String
    }
  },
  methods: {
    sendVal (val) {
      this.$emit('sendVal', val)
    },
    foo () {
      console.log('我是子组件的方法')
    },
    bar () {
      console.log(this.$parent)
      this.$parent.names.push('张三')
    },
    post () {
      this.$emit('update:aa', '子组件的值')
    }
  }
}
</script>
